/*
 * Created on Jun 24, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.peterrussell.contractionTimer;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

import org.peterrussell.contractionTimer.model.ContractionTimeDTO;

/**
 * @author peterr
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class LCDController implements UIController {

	private int START = 1;
	private int STOP = 2;
	
    private MainCanvas canvas;
    private int buttonStatus;
	/**
	 * 
	 */
	public LCDController() {
		canvas = new MainCanvas();

	}
	
	public void start() {
        Display display = Display.getDisplay(MIDletSingleton.getMIDlet());
        display.setCurrent(canvas);
        this.buttonStatus = START;
	}
	
	public void exit() {
		MIDlet app = MIDletSingleton.getMIDlet();
        //app.destroyApp(false);
        app.notifyDestroyed();

	}
	
	/* (non-Javadoc)
	 * @see org.peterrussell.contractionTimer.UIController#startContractionTimer()
	 */
	public void startContractionTimer() {
		if (buttonStatus == START) {
	        canvas.removeCommand(canvas.startCommand);
            canvas.addCommand(canvas.stopCommand);
            buttonStatus = STOP;
		}
	}

	/* (non-Javadoc)
	 * @see org.peterrussell.contractionTimer.UIController#stopContractionTimer()
	 */
	public void stopContractionTimer() {
	}

	/* (non-Javadoc)
	 * @see org.peterrussell.contractionTimer.UIController#refreshContractionTimer()
	 */
	public void refreshContractionTimer(ContractionTimeDTO dto) {
		canvas.setContactionTime(dto.getContractionTime());
		// TODO: restrict refresh area to only that requiring repaint
		canvas.repaint();
	}

	/* (non-Javadoc)
	 * @see org.peterrussell.contractionTimer.UIController#startBetweenContractionTimer()
	 */
	public void startBetweenContractionTimer() {
	}

	/* (non-Javadoc)
	 * @see org.peterrussell.contractionTimer.UIController#stopBetweenContractionTimer()
	 */
	public void stopBetweenContractionTimer() {
		
	}

	/* (non-Javadoc)
	 * @see org.peterrussell.contractionTimer.UIController#refreshBetweenContractionTimer()
	 */
	public void refreshBetweenContractionTimer(ContractionTimeDTO dto) {
		canvas.setBetweenContactionTime(dto.getBetweenContractionTime());
		// TODO: restrict refresh area to only that requiring repaint
		canvas.repaint();
	}
}
